package com.zyx.spring5msb.iocforward.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * @author Yaxi.Zhang
 * @since 2021/9/27 15:48
 */
public class MyBeanPostProcessor implements BeanPostProcessor {
    /**
     * 在每一个对象的初始化方法前面执行
     * @param bean 表示创建的具体对象
     * @param beanName bean对象的id值
     */
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("before initialization, bean = " + bean + ", bead id = " + beanName);
        return bean;
    }

    /**
     * 在每一个对象的初始化方法后面执行
     */
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("after initialization, bean = " + bean + ", bead id = " + beanName);
        return bean;
    }
}
